


/*
'===============================================================================
'  LinqHelper.DAO.CategoryBase
'===============================================================================
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using LinqHelper;
using LinqHelper.Entity;
using LinqHelper.DAO;

namespace LinqHelper.DAO
{
	public class LqCategoryBase
	{
		public LqProvider provider = new LqProvider();
		
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		public LqCategoryBase()
		{
			// Nothing for now.
		}
		
		public void Insert(LqCategoryEntity obj)
		{
			provider.GetTable<LqCategoryEntity>().InsertOnSubmit(obj);
            provider.SubmitChanges();
		}

		public void Update(LqCategoryEntity _obj)
		{
			var q = from obj in provider.GetTable<LqCategoryEntity>()
                    where obj.Id == _obj.Id
                    select obj;
			LqCategoryEntity tmp = q.First<LqCategoryEntity>();
			
			tmp.CatId = _obj.CatId;
			tmp.CategoryName = _obj.CategoryName;
			tmp.CreatedDate = _obj.CreatedDate;
			tmp.MenuId = _obj.MenuId;
			tmp.OrderIndex = _obj.OrderIndex;
			provider.SubmitChanges();
		}
		
		public void Delete(LqCategoryEntity obj)
		{
			provider.GetTable<LqCategoryEntity>().DeleteOnSubmit(obj);
            provider.SubmitChanges();
		}
		
		
		public void DeleteById(Guid Id)
		{
			var q = from obj in provider.GetTable<LqCategoryEntity>()
                    where obj.Id == Id
                    select obj;
					
            LqCategoryEntity ob = (LqCategoryEntity)q.First<LqCategoryEntity>();
            provider.GetTable<LqCategoryEntity>().DeleteOnSubmit(ob);
            provider.SubmitChanges();
		}
		
		
		public void DeleteByCatId(string CatId)
		{
			var q = from obj in provider.GetTable<LqCategoryEntity>()
                    where obj.CatId == CatId
                    select obj;
					
            LqCategoryEntity ob = (LqCategoryEntity)q.First<LqCategoryEntity>();
            provider.GetTable<LqCategoryEntity>().DeleteOnSubmit(ob);
            provider.SubmitChanges();
		}
		
		
		public void DeleteByCategoryName(string CategoryName)
		{
			var q = from obj in provider.GetTable<LqCategoryEntity>()
                    where obj.CategoryName == CategoryName
                    select obj;
					
            LqCategoryEntity ob = (LqCategoryEntity)q.First<LqCategoryEntity>();
            provider.GetTable<LqCategoryEntity>().DeleteOnSubmit(ob);
            provider.SubmitChanges();
		}
		
		
		public void DeleteByCreatedDate(DateTime CreatedDate)
		{
			var q = from obj in provider.GetTable<LqCategoryEntity>()
                    where obj.CreatedDate == CreatedDate
                    select obj;
					
            LqCategoryEntity ob = (LqCategoryEntity)q.First<LqCategoryEntity>();
            provider.GetTable<LqCategoryEntity>().DeleteOnSubmit(ob);
            provider.SubmitChanges();
		}
		
		
		public void DeleteByMenuId(string MenuId)
		{
			var q = from obj in provider.GetTable<LqCategoryEntity>()
                    where obj.MenuId == MenuId
                    select obj;
					
            LqCategoryEntity ob = (LqCategoryEntity)q.First<LqCategoryEntity>();
            provider.GetTable<LqCategoryEntity>().DeleteOnSubmit(ob);
            provider.SubmitChanges();
		}
		
		
		public void DeleteByOrderIndex(int OrderIndex)
		{
			var q = from obj in provider.GetTable<LqCategoryEntity>()
                    where obj.OrderIndex == OrderIndex
                    select obj;
					
            LqCategoryEntity ob = (LqCategoryEntity)q.First<LqCategoryEntity>();
            provider.GetTable<LqCategoryEntity>().DeleteOnSubmit(ob);
            provider.SubmitChanges();
		}
		
		
		public LqCategoryEntity SelectOne(Guid Id)
		{
			var query = from obj in provider.GetTable<LqCategoryEntity>()
                        where obj.Id == Id
                        select obj;
            return query.First<LqCategoryEntity>();
		}

		public List<LqCategoryEntity> SelectAll()
		{
			var query = from obj in provider.GetTable<LqCategoryEntity>()
                        select obj;
            return query.ToList<LqCategoryEntity>();
		}
		
		
		public List<LqCategoryEntity> SelectById(Guid Id)
		{
			var query = from obj in provider.GetTable<LqCategoryEntity>()
                        where obj.Id == Id
                        select obj;
            return query.ToList<LqCategoryEntity>();
		}
		
		
		public List<LqCategoryEntity> SelectByCatId(string CatId)
		{
			var query = from obj in provider.GetTable<LqCategoryEntity>()
                        where obj.CatId == CatId
                        select obj;
            return query.ToList<LqCategoryEntity>();
		}
		
		
		public List<LqCategoryEntity> SelectByCategoryName(string CategoryName)
		{
			var query = from obj in provider.GetTable<LqCategoryEntity>()
                        where obj.CategoryName == CategoryName
                        select obj;
            return query.ToList<LqCategoryEntity>();
		}
		
		
		public List<LqCategoryEntity> SelectByCreatedDate(DateTime CreatedDate)
		{
			var query = from obj in provider.GetTable<LqCategoryEntity>()
                        where obj.CreatedDate == CreatedDate
                        select obj;
            return query.ToList<LqCategoryEntity>();
		}
		
		
		public List<LqCategoryEntity> SelectByMenuId(string MenuId)
		{
			var query = from obj in provider.GetTable<LqCategoryEntity>()
                        where obj.MenuId == MenuId
                        select obj;
            return query.ToList<LqCategoryEntity>();
		}
		
		
		public List<LqCategoryEntity> SelectByOrderIndex(int OrderIndex)
		{
			var query = from obj in provider.GetTable<LqCategoryEntity>()
                        where obj.OrderIndex == OrderIndex
                        select obj;
            return query.ToList<LqCategoryEntity>();
		}
		
		
		

	}
}
